import java.io.*;
import java.util.Scanner;

public class Demo5 {
    //实现文件复制
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入文件路径");
        String rootpath=scanner.next();
        File file=new File(rootpath);
        if(!file.isFile()){
            System.out.println("输入错误");
            return;
        }
        System.out.println("请输入目标路径");
        Scanner scanner1=new Scanner(System.in);
        String destPath=scanner1.next();
        File destFile=new File(destPath);
        if(!destFile.getParentFile().isDirectory()){
            System.out.println("输入错误");
            return;
        }
        try (InputStream stream=new FileInputStream(file);
             OutputStream stream1=new FileOutputStream(destFile)){
            while (true){
                byte[] buffer=new byte[1024];
                int n=stream.read(buffer);
                if(n==-1){
                    break;
                }
                stream1.write(buffer,0,n);
            }

        }catch (IOException e){
            e.printStackTrace();
        }

    }
}
